package com.home.common;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.home.common.attributes.UserAttribute;
import com.home.entity.User;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class BaseAction extends ActionSupport {
    public ActionContext getActionContext() {
        return ActionContext.getContext();
    }

    public HttpServletRequest getRequest() {
        return (HttpServletRequest) ServletActionContext.getRequest();
    }

    public HttpServletResponse getResponse() {
        return (HttpServletResponse) ServletActionContext.getResponse();
    }

    @SuppressWarnings("rawtypes")
    public Map getSession() {
        return getActionContext().getSession();
    }

    public User getUser() {
        User u = (User) getSession().get(UserAttribute.SESSION_USER);
        return u == null ? new User() : u;
    }
}
